home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / byacc 1.8.2 / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  9.0 KB  |  372 lines  |  [TEXT/R*ch]

  1. #if __STDC__ || defined(__cplusplus)
  2. #define _P_(s) s
  3. #else
  4. #define _P_(s) ()
  5. #endif
  6.  
  7. #include <assert.h>
  8. #include <ctype.h>
  9. #include <stdio.h>
  10.  
  11. #if __STDC__
  12. #include <stdlib.h>
  13. #include <stddef.h>
  14. #include <string.h>
  15. #include <limits.h>
  16.  
  17. #ifdef _AMIGA
  18. #define AMIGA
  19. #endif
  20.  
  21. #endif
  22.  
  23. /*  machine-dependent definitions            */
  24. /*  the following definitions are for the Tahoe        */
  25. /*  they might have to be changed for other machines    */
  26.  
  27. /*  MAXCHAR is the largest unsigned character value    */
  28. /*  MAXSHORT is the largest value of a C short        */
  29. /*  MINSHORT is the most negative value of a C short    */
  30. /*  MAXTABLE is the maximum table size            */
  31. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  32. /*  WORDSIZE computes the number of words needed to    */
  33. /*    store n bits                    */
  34. /*  BIT returns the value of the n-th bit starting    */
  35. /*    from r (0-indexed)                */
  36. /*  SETBIT sets the n-th bit starting from r        */
  37.  
  38. #ifdef AMIGA
  39. #define MAXCHAR        UCHAR_MAX
  40. #define    MAXSHORT    SHRT_MAX
  41. #define MINSHORT    SHRT_MIN
  42. #else
  43. #define    MAXCHAR        255
  44. #define    MAXSHORT    32767
  45. #define MINSHORT    -32768
  46. #endif
  47. #define MAXTABLE    32500
  48. #define BITS_PER_WORD    32
  49. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  50. #define    BIT(r, n)    ((((r)[(n)>>5])>>((n)&31))&1)
  51. #define    SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  52.  
  53.  
  54. /*  character names  */
  55.  
  56. #define    NUL        '\0'    /*  the null character    */
  57. #define    NEWLINE        '\n'    /*  line feed  */
  58. #define    SP        ' '    /*  space  */
  59. #define    BS        '\b'    /*  backspace  */
  60. #define    HT        '\t'    /*  horizontal tab  */
  61. #define    VT        '\013'    /*  vertical tab  */
  62. #define    CR        '\r'    /*  carriage return  */
  63. #define    FF        '\f'    /*  form feed  */
  64. #define    QUOTE        '\''    /*  single quote  */
  65. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  66. #define    BACKSLASH    '\\'    /*  backslash  */
  67.  
  68.  
  69. /* defines for constructing filenames */
  70.  
  71. #define CODE_SUFFIX    0
  72. #define DEFINES_SUFFIX    1
  73. #define OUTPUT_SUFFIX    2
  74. #define VERBOSE_SUFFIX    3
  75.  
  76.  
  77. /* keyword codes */
  78.  
  79. #define TOKEN 0
  80. #define LEFT 1
  81. #define RIGHT 2
  82. #define NONASSOC 3
  83. #define MARK 4
  84. #define TEXT 5
  85. #define TYPE 6
  86. #define START 7
  87. #define UNION 8
  88. #define IDENT 9
  89.  
  90.  
  91. /*  symbol classes  */
  92.  
  93. #define UNKNOWN 0
  94. #define TERM 1
  95. #define NONTERM 2
  96.  
  97.  
  98. /*  the undefined value     */
  99.  
  100. #define UNDEFINED (-1)
  101.  
  102.  
  103. /*  action codes  */
  104.  
  105. #define SHIFT 1
  106. #define REDUCE 2
  107.  
  108.  
  109. /*  character macros  */
  110.  
  111. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  112. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  113. #define    NUMERIC_VALUE(c)    ((c) - '0')
  114.  
  115.  
  116. /*  symbol macros  */
  117.  
  118. #define ISTOKEN(s)    ((s) < start_symbol)
  119. #define ISVAR(s)    ((s) >= start_symbol)
  120.  
  121.  
  122. /*  storage allocation macros  */
  123.  
  124. #define CALLOC(k,n)    (my_calloc((unsigned)(k),(unsigned)(n)))
  125. #define    FREE(x)        (free((char*)(x)))
  126. #define MALLOC(n)    (my_malloc((unsigned)(n)))
  127. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  128. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  129. #define REALLOC(p,n)    (my_realloc((char*)(p),(unsigned)(n)))
  130.  
  131.  
  132. /*  the structure of a symbol table entry  */
  133.  
  134. typedef struct bucket bucket;
  135. struct bucket
  136. {
  137.     struct bucket *link;
  138.     struct bucket *next;
  139.     char *name;
  140.     char *tag;
  141.     short value;
  142.     short index;
  143.     short prec;
  144.     char class;
  145.     char assoc;
  146. };
  147.  
  148.  
  149. /*  the structure of the LR(0) state machine  */
  150.  
  151. typedef struct core core;
  152. struct core
  153. {
  154.     struct core *next;
  155.     struct core *link;
  156.     short number;
  157.     short accessing_symbol;
  158.     short nitems;
  159.     short items[1];
  160. };
  161.  
  162.  
  163. /*  the structure used to record shifts     */
  164.  
  165. typedef struct shifts shifts;
  166. struct shifts
  167. {
  168.     struct shifts *next;
  169.     short number;
  170.     short nshifts;
  171.     short shift[1];
  172. };
  173.  
  174.  
  175. /*  the structure used to store reductions  */
  176.  
  177. typedef struct reductions reductions;
  178. struct reductions
  179. {
  180.     struct reductions *next;
  181.     short number;
  182.     short nreds;
  183.     short rules[1];
  184. };
  185.  
  186.  
  187. /*  the structure used to represent parser actions  */
  188.  
  189. typedef struct action action;
  190. struct action
  191. {
  192.     struct action *next;
  193.     short symbol;
  194.     short number;
  195.     short prec;
  196.     char action_code;
  197.     char assoc;
  198.     char suppressed;
  199. };
  200.  
  201. /* target language is one of these */
  202. typedef enum { C, PERL } Language;
  203.  
  204. /* global variables */
  205.  
  206. extern char dflag;
  207. extern char lflag;
  208. extern char rflag;
  209. extern char tflag;
  210. extern char vflag;
  211.  
  212. extern Language language;
  213.  
  214. extern char *myname;
  215. extern char *cptr;
  216. extern char *line;
  217. extern int lineno;
  218. extern int outline;
  219.  
  220. extern char **banner[];
  221. extern char **tables[];
  222. extern char **header[];
  223. extern char **body[];
  224. extern char **trailer[];
  225.  
  226. extern int  prefix_changed;
  227. extern char *define_prefix;
  228. extern char *symbol_prefix;
  229.  
  230. extern char *action_file_name;
  231. extern char *code_file_name;
  232. extern char *defines_file_name;
  233. extern char *input_file_name;
  234. extern char *output_file_name;
  235. extern char *text_file_name;
  236. extern char *union_file_name;
  237. extern char *verbose_file_name;
  238.  
  239. extern FILE *action_file;
  240. extern FILE *code_file;
  241. extern FILE *defines_file;
  242. extern FILE *input_file;
  243. extern FILE *output_file;
  244. extern FILE *text_file;
  245. extern FILE *union_file;
  246. extern FILE *verbose_file;
  247.  
  248. extern int nitems;
  249. extern int nrules;
  250. extern int nsyms;
  251. extern int ntokens;
  252. extern int nvars;
  253. extern int ntags;
  254.  
  255. extern char unionized;
  256. extern char line_format[];
  257.  
  258. extern int   start_symbol;
  259. extern char  **symbol_name;
  260. extern short *symbol_value;
  261. extern short *symbol_prec;
  262. extern char  *symbol_assoc;
  263.  
  264. extern short *ritem;
  265. extern short *rlhs;
  266. extern short *rrhs;
  267. extern short *rprec;
  268. extern char  *rassoc;
  269.  
  270. extern short **derives;
  271. extern char *nullable;
  272.  
  273. extern bucket *first_symbol;
  274. extern bucket *last_symbol;
  275.  
  276. extern int nstates;
  277. extern core *first_state;
  278. extern shifts *first_shift;
  279. extern reductions *first_reduction;
  280. extern short *accessing_symbol;
  281. extern core **state_table;
  282. extern shifts **shift_table;
  283. extern reductions **reduction_table;
  284. extern unsigned *LA;
  285. extern short *LAruleno;
  286. extern short *lookaheads;
  287. extern short *goto_map;
  288. extern short *from_state;
  289. extern short *to_state;
  290.  
  291. extern action **parser;
  292. extern int SRtotal;
  293. extern int RRtotal;
  294. extern short *SRconflicts;
  295. extern short *RRconflicts;
  296. extern short *defred;
  297. extern short *rules_used;
  298. extern short nunused;
  299. extern short final_state;
  300.  
  301. /* global functions */
  302.  
  303. extern char *   allocate _P_((unsigned n));
  304. extern void     closure _P_((short *nucleus, int n));
  305. extern void     create_symbol_table _P_((void));
  306. extern void     default_action_warning _P_((void));
  307. extern void     dollar_error _P_((int a_lineno, char *a_line, char *a_cptr));
  308. extern void     dollar_warning _P_((int a_lineno, int i));
  309. extern void     done _P_((int k));
  310. extern void     fatal _P_((char *msg));
  311. extern void     finalize_closure _P_((void));
  312. extern void     free_derives _P_((void));
  313. extern void     free_nullable _P_((void));
  314. extern void     free_parser _P_((void));
  315. extern void     free_symbol_table _P_((void));
  316. extern void     free_symbols _P_((void));
  317. extern void     illegal_character _P_((char *c_cptr));
  318. extern void     illegal_tag _P_((int t_lineno, char *t_line, char *t_cptr));
  319. extern void     lalr _P_((void));
  320. extern bucket * lookup _P_((char *name));
  321. extern void     lr0 _P_((void));
  322. extern bucket * make_bucket _P_((char *name));
  323. extern void     make_parser _P_((void));
  324. extern char *   my_calloc _P_((unsigned k, unsigned n));
  325. extern char *   my_malloc _P_((unsigned n));
  326. extern char *   my_realloc _P_((char *p, unsigned n));
  327. extern void     no_grammar _P_((void));
  328. extern void     no_space _P_((void));
  329. extern void     open_error _P_((char *filename));
  330. extern void     output _P_((void));
  331. extern void     over_unionized _P_((char *u_cptr));
  332. extern void     prec_redeclared _P_((void));
  333. extern void     print_pos _P_((char *st_line, char *st_cptr));
  334. extern void     reader _P_((void));
  335. extern void     reflexive_transitive_closure _P_((unsigned *R, int n));
  336. extern void     reprec_warning _P_((char *s));
  337. extern void     restarted_warning _P_((void));
  338. extern void     retyped_warning _P_((char *s));
  339. extern void     revalued_warning _P_((char *s));
  340. extern void     set_first_derives _P_((void));
  341. extern void     syntax_error _P_((int st_lineno, char *st_line, char *st_cptr));
  342. extern void     terminal_lhs _P_((int s_lineno));
  343. extern void     terminal_start _P_((char *s));
  344. extern void     tokenized_start _P_((char *s));
  345. extern void     undefined_goal _P_((char *s));
  346. extern void     undefined_symbol_warning _P_((char *s));
  347. extern void     unexpected_EOF _P_((void));
  348. extern void     unknown_rhs _P_((int i));
  349. extern void     unterminated_action _P_((int a_lineno, char *a_line, char *a_cptr));
  350. extern void     unterminated_comment _P_((int c_lineno, char *c_line, char *c_cptr));
  351. extern void     unterminated_string _P_((int s_lineno, char *s_line, char *s_cptr));
  352. extern void     unterminated_text _P_((int t_lineno, char *t_line, char *t_cptr));
  353. extern void     unterminated_union _P_((int u_lineno, char *u_line, char *u_cptr));
  354. extern void     untyped_lhs _P_((void));
  355. extern void     untyped_rhs _P_((int i, char *s));
  356. extern void     used_reserved _P_((char *s));
  357. extern void     verbose _P_((void));
  358. extern void     write_section _P_((char **section[]));
  359.  
  360. /* system variables */
  361.  
  362. extern int errno;
  363.  
  364.  
  365. /* system functions */
  366.  
  367. #if __STDC__ != 1
  368. extern void free();
  369. extern char *strcpy();
  370. extern char *strrchr();
  371. #endif
  372.